package cn.trigram.asserts;

import cn.trigram.exception.AssetException;
import cn.trigram.lang.ObjectUtil;
import java.util.Collection;
import java.util.Map;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

public class AssertUtil {

  public static void assertArgs(boolean predict, String assertMessage) {

    if (!predict) {
      throw new AssetException(assertMessage);
    }
  }

  public static void assertNotNull(Object o, String assertMessage) {

    assertArgs(ObjectUtil.isNotNull(o), assertMessage);
  }

  public static void assertNull(Object o, String assertMessage) {

    assertArgs(ObjectUtil.isNull(o), assertMessage);
  }

  public static void assertNotEmpty(CharSequence str, String assertMessage) {

    assertArgs(StringUtils.isNotEmpty(str), assertMessage);
  }

  public static void assertEmpty(CharSequence str, String assertMessage) {

    assertArgs(StringUtils.isEmpty(str), assertMessage);
  }

  public static void assertBlank(CharSequence str, String assertMessage) {

    assertArgs(StringUtils.isBlank(str), assertMessage);
  }

  public static void assertNotBlank(CharSequence str, String assertMessage) {

    assertArgs(StringUtils.isNotBlank(str), assertMessage);
  }

  public static void assertNotEmpty(Collection<?> list, String assertMessage) {

    assertArgs(CollectionUtils.isNotEmpty(list), assertMessage);
  }

  public static void assertEmpty(Collection<?> list, String assertMessage) {

    assertArgs(CollectionUtils.isEmpty(list), assertMessage);
  }
  public static void assertNotEmpty(Map<?,?> map, String assertMessage) {

    assertArgs(MapUtils.isNotEmpty(map), assertMessage);
  }

  public static void assertEmpty(Map<?,?> map, String assertMessage) {

    assertArgs(MapUtils.isEmpty(map), assertMessage);
  }

}
